package expressions.slogo;

import java.util.List;
import parsing.Separates;
import parsing.Token;
import expressions.Operator;

@Token(regex = "\\^")
@Separates
public class Power extends Operator<Double>
{

    public Power()
    {
        super(2);
    }

    /**
     * Hopefully this is the right way to make ^ left-associative
     */
    @Override
    protected boolean hasHigherPriority(Operator<Double> op)
    {
        return op.priority() >= priority();
    }

    @Override
    public int priority()
    {
        return Priority.ARITHMETIC.adjust(Modifier.HIGHEST);
    }

    @Override
    protected Double combineResults(List<Double> results)
    {
        return Math.pow(results.get(0), results.get(1));
    }

}
